<template>
  <!--  模糊搜索表格-->
  <el-table :data="tableData" style="width: 100%">
    <el-table-column fixed prop="id" label="文章id" width="150"/>
    <el-table-column prop="authorId" label="用户Id" width="150" />
    <el-table-column prop="title" label="文章标题" width="200" />
    <!--      <el-table-column prop="coverImage" label="封面图片" width="250" />-->
    <el-table-column prop="summary" label="简介" width="300" />
    <el-table-column prop="createDate" label="创建时间" width="300" />
    <el-table-column fixed="right" label="Operations" width="120">
      <template #default="data">
        <el-button size="small" @click="lookButton(data.row.id)">查看
        </el-button>
      </template>
    </el-table-column>
  </el-table>

  <div class="demo-pagination-block">
    <div class="demonstration"></div>
    <h4>总页数&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    </h4>
    <el-pagination
        v-model:current-page=current
        :page-size=size
        :small="small"
        :disabled="disabled"
        :background="background"
        layout="total, prev, pager, next"
        :total=total
        @size-change="getSizeChange"
        @current-change="getCurrentPage"
    />
  </div>
</template>

<script>
import request from "@/utils/request";
import router from "@/router";
import displayArticleView from "@/views/body/displayArticleView";

export default {
  name: "LikeSearchTable",
  components: {
    displayArticleView
  },

  created() {
    this.load()
  },

  methods: {
    load() {
      //模糊查询
      let articleBody=router.currentRoute.value.query.articleBody
      request.get("/articles/searchByArticleBody/"+articleBody+"/"+this.current).then(res => {
        console.log(res.data)
        if (res.data == 500) {
          alert("返回错误,返回文章检索页面!")
          router.push("/ArticleSearchView")
        } else {
          if (res.data.records!=null){
            this.tableData=res.data.records
            this.total=res.data.total
            this.size=res.data.size
            this.pages=res.data.pages
          }
          else {
            this.tableData=res.data
          }
        }
      })
    },

    lookButton(articleId){
      console.log("点击："+articleId)
      router.push({
        name:"displayArticleView",
        query:{
          articleId: articleId,
        }
      })
    },

    getCurrentPage(current){
      let articleBody=router.currentRoute.value.query.articleBody
      request.get("/articles/searchByArticleBody/"+articleBody+current).then(res => {
        console.log(res.data)
        if (res.data == 500) {
          alert("用户id返回错误,返回热门文章页面!")
          router.push("/HotViewView")
        } else {
          this.articleList=res.data.records
          console.log(res.data.records)
          this.total=res.data.total
          this.size=res.data.size
          this.pages=res.data.pages
        }
      })
    },

  },

  data(){
    return{
      tableData:[
        {
          id:1,
          authorId:'',
          title:'',
          summary:'',
          coverImage:'',
          weight:'',
          articleBody:'',
        }
      ],

      userId: '',
      total: 6,
      size: 12,
      current: 1,
      pages: 10,
    }
  }

}
</script>

<style >

</style>